﻿$(document).ready(function () {
    $(".txtBrows").blur(function () {

        var offset = $(this).offset();
        var xVal = offset.left;
        var yVal = offset.top;
        var sUrl = $(this).val();
        var sTextAreId = $(this).next().attr("id");
        
        if (sUrl !== 'http://' & sUrl !== '') {
            ShowHideLoading(true, xVal, yVal + 30);

            $.ajax({
                url: "Clustering.aspx/GetContentFromUrl",
                type: "POST",
                data: JSON.stringify({ 'sUrl': sUrl }),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) { GetContentSucc(data, sTextAreId); },
                error: function () {
                }
            });
        }


    });
    $(".txtBrows").focusin(function () {
        $(this).val("");
    }).focusout(function () {
        if ($(this).val() === '')
            $(this).val("http://");
    });
});

function ShowHideLoading(bCheck,xVal,yVal) {
    if (bCheck === true) {
        $('.loading').show();
        $('.loading').css({ top: yVal, left: xVal });
    }
    else
        $('.loading').hide();

}

function GetContentSucc(data, sTextAreId) {
    var sRes = data.d;
    $("#" + sTextAreId).val(sRes);
    ShowHideLoading(false);
}